<?php if(!defined('EMLOG_ROOT')) {exit('error!');} ?>
<?php
//widget：blogger
function widget_blogger($title){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$name = $user_cache[1]['mail'] != '' ? "<a href=\"mailto:".$user_cache[1]['mail']."\">".$user_cache[1]['name']."</a>" : $user_cache[1]['name'];?>
	<li class="emer">
	<h3><span onclick="showhidediv('bloggerinfo')"><?php echo $title; ?></span></h3>
	<div id="bloggerinfoimg">
	<?php if (!empty($user_cache[1]['photo']['src'])): ?>
	<img src="<?php echo BLOG_URL.$user_cache[1]['photo']['src']; ?>" width="<?php echo $user_cache[1]['photo']['width']; ?>" height="<?php echo $user_cache[1]['photo']['height']; ?>" alt="blogger" />
	<?php endif;?>
	<p><b><?php echo $name; ?></b></p>
	<p><?php echo $user_cache[1]['des']; ?></p>
	</div>
	</li>
<?php }?>
<?php
//widget：日历
function widget_calendar($title){
?>
	<li>
	<h3><span onclick="showhidediv('calendar')"><?php echo $title; ?></span></h3>
	<div id="calendar">
	</div>
	<script>sendinfo('<?php echo Calendar::url(); ?>','calendar');</script>
	</li>
<?php }?>
<?php
//widget：标签
function widget_tag($title){
	global $CACHE;
	$tag_cache = $CACHE->readCache('tags');?>
    <li>
	<h3><span onclick="showhidediv('blogtags')"><?php echo $title; ?></span></h3>
	<ul id="blogtags">
	<li>
	<?php foreach($tag_cache as $value): ?>
		<span style="font-size:<?php echo $value['fontsize']; ?>px; height:30px;">
		<a href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇日志"><?php echo $value['tagname']; ?></a></span>
	<?php endforeach; ?>
	</li>
	</ul>
    </li>
<?php }?>
<?php
//widget：分类
function widget_sort($title){
	global $CACHE;
	$sort_cache = $CACHE->readCache('sort');?>
	<li class="blogsor">
	<h3><span onclick="showhidediv('blogsort')"><?php echo $title; ?></span></h3>
	<ul>
	<?php foreach($sort_cache as $value): ?>
    <li> 
	<a href="<?php echo Url::sort($value['sid']); ?>"><?php echo $value['sortname']; ?>(<?php echo $value['lognum'] ?>)</a>
	<a href="<?php echo BLOG_URL; ?>rss.php?sort=<?php echo $value['sid']; ?>"><img align="absmiddle" src="<?php echo TEMPLATE_URL; ?>img/rss.png" alt="订阅该分类"/></a>
	</li>
	<?php endforeach; ?>
	</ul>
    </li>
<?php }?>
<?php
//widget：最新碎语
function widget_twitter($title){
	global $CACHE; 
	$newtws_cache = $CACHE->readCache('newtw');
	$istwitter = Option::get('istwitter'); ?>
	<li class="twitter">
		<h3><span onclick="showhidediv('twitter')"><?php echo $title; ?></span></h3>
        	<ul id="twitter">
		<?php foreach($newtws_cache as $value): ?>
		<li><?php echo $value['t']; ?><p><?php echo smartDate($value['date']); ?> </p></li>
		<?php endforeach; ?>
		<?php if ($istwitter == 'y') :?>
		<p style="text-align:right"><a href="<?php echo BLOG_URL . 't/'; ?>">更多&raquo;</a></p>
		<?php endif;?>
    </ul>
	</li>
<?php } ?>
<?php
//widget：最新评论
function widget_newcomm($title){
	global $CACHE;
	$com_cache = $CACHE->readCache('comment');?>
    <li>
    <h3><span onclick="showhidediv('newcomment')"><?php echo $title; ?></span></h3>
	<ul  class="comment">
	<?php 
	foreach($com_cache as $value): 
	$url = Url::log($value['gid']).'#'.$value['cid'];
	?>
	<li><?php echo $value['name']; ?> 
	<br /><a href="<?php echo $url; ?>"><?php echo $value['content']; ?></a></li>
	<?php endforeach; ?>
	</ul>
    </li>
<?php }?>
<?php
//widget：最新日志
function widget_newlog($title){
	global $CACHE;
	$newLogs_cache = $CACHE->readCache('newlog');?>
<li>
	<h3><span onclick="showhidediv('newlog')"><?php echo $title; ?></span></h3>
	<ul id="newlog">
	<?php foreach($newLogs_cache as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
</li>
<?php }?>
<?php
//widget：随机日志
function widget_random_log($title){
	$index_randlognum = Option::get('index_randlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getRandLog($index_randlognum);?>
<li>
	<h3><span onclick="showhidediv('randlog')"><?php echo $title; ?></span></h3>
	<ul id="randlog">
	<?php foreach($randLogs as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
</li>
<?php }?>
<?php
//widget：搜索
function widget_search($title){ ?>
	<li class="logserch">
	<h3><span onclick="showhidediv('logserch')"><?php echo $title; ?></span></h3>
	<form name="keyform" method="get" action="<?php echo BLOG_URL; ?>index.php"><p>
	<input class="sou" name="keyword"  type="text" value=""/>
	<input  class="sou_b" type="submit" id="logserch_logserch" value="GO" />
	</form>
	</li>
<?php } ?>
<?php
//widget：归档
function widget_archive($title){
	global $CACHE;
	$dang_cache = $CACHE->readCache('record');?>
<li>
	<h3><span onclick="showhidediv('record')"><?php echo $title; ?></span></h3>
	<ul id="record">
	<?php foreach($dang_cache as $value): ?>
	<li><a href="<?php echo Url::record($value['date']); ?>"><?php echo $value['record']; ?>(<?php echo $value['lognum']; ?>)</a></li>
	<?php endforeach; ?>		
	</ul>
</li>
<?php } ?>
<?php
//widget：自定义组件
function widget_custom_text($title, $content, $id){ ?>
<li id="zdy">
	<h3><span onclick="showhidediv('<?php echo $id; ?>')"><?php echo $title; ?></span></h3>
	<ul id="<?php echo $id; ?>">
	<li><?php echo $content; ?></li>
	</ul>
</li>
<?php } ?>
<?php
//widget：链接
function widget_link($title){
	global $CACHE;
	$link_cache = $CACHE->readCache('link');?>
<li>
	<h3><span onclick="showhidediv('link')"><?php echo $title; ?></span></h3>
	<ul id="link">
	<?php foreach($link_cache as $value): ?>     	
	<li><a href="<?php echo $value['url']; ?>" title="<?php echo $value['des']; ?>" target="_blank"><?php echo $value['link']; ?></a></li>
	<?php endforeach; ?>
	</ul>
</li>
<?php }?>
<?php
//blog：置顶
function topflg($istop){
	$topflg = $istop == 'y' ? "<img src=\"".TEMPLATE_URL."/img/import.gif\" align=\"absmiddle\"  title=\"置顶日志\" /> " : '';
	echo $topflg;
}
?>
<?php
//blog：编辑
function editflg($logid,$author){
	$editflg = ROLE == 'admin' || $author == UID ? '<a href="'.BLOG_URL.'admin/write_log.php?action=edit&gid='.$logid.'">编辑</a>' : '';
	echo $editflg;
}
?>
<?php 
//blog：分类
function blog_sort($blogid){
	global $CACHE; 
	$log_cache_sort = $CACHE->readCache('logsort');?>
	<?php if(!empty($log_cache_sort[$blogid])): ?>
	[<a href="<?php echo Url::sort($log_cache_sort[$blogid]['id']); ?>"><?php echo $log_cache_sort[$blogid]['name']; ?></a>]
	<?php endif;?>
<?php }?>
<?php
//blog：文件附件
function blog_att($blogid){
	global $CACHE;
	$log_cache_atts = $CACHE->readCache('logatts'); 
	$att = '';
	if(!empty($log_cache_atts[$blogid])){
		$att .= '附件下载：';
		foreach($log_cache_atts[$blogid] as $val){
			$att .= '<br /><a href="'.BLOG_URL.$val['url'].'" target="_blank">'.$val['filename'].'</a> '.$val['size'];
		}
	}
	echo $att;
}
?>
<?php
//blog：日志标签
function blog_tag($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid]))
	{
		$tag = '标签:';
		foreach ($log_cache_tags[$blogid] as $value)
		{
			$tag .= "	<a href=\"".BLOG_URL."?tag=".$value['tagurl']."\">".$value['tagname'].'</a>';
		}
		echo $tag;
	}
}
?>
<?php
//blog：日志作者
function blog_author($uid){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$author = $user_cache[$uid]['name'];
	$mail = $user_cache[$uid]['mail'];
	$des = $user_cache[$uid]['des'];
	$title = !empty($mail) || !empty($des) ? "title=\"$des $mail\"" : '';
	echo '<a href="'.Url::author($uid)."\" $title>$author</a>";
}
?>
<?php
//blog：相邻日志
function neighbor_log($neighborLog){
	extract($neighborLog);?>
	<?php if($prevLog):?>
	&laquo; <a href="<?php echo Url::log($prevLog['gid']) ?>"><?php echo $prevLog['title'];?></a>
	<?php endif;?>
	<?php if($nextLog && $prevLog):?>
		|
	<?php endif;?>
	<?php if($nextLog):?>
		 <a href="<?php echo Url::log($nextLog['gid']) ?>"><?php echo $nextLog['title'];?></a>&raquo;
	<?php endif;?>
<?php }?>
<?php
//blog：引用通告
function blog_trackback($tb, $tb_url, $allow_tb){
	 ?>
	<?php if($allow_tb == 'y'):?>	
        <div class="comment">
        <div class="top">    
        	<div id="trackback_address">
			引用地址：<input type="text" style="width:350px" class="input" value="<?php echo $tb_url; ?>">
			</div>
 	   </div>
	<?php endif; ?>
	<?php foreach($tb as $key=>$value):?>
		<ul id="trackback">
		<li><a href="<?php echo $value['url'];?>" target="_blank"><?php echo $value['title'];?></a></li>
		<li>BLOG: <?php echo $value['blog_name'];?></li><li><?php echo $value['date'];?></li>
		</ul>
	<?php endforeach; ?>
		<?php if($allow_tb == 'y'):?>	
    <div class="bottom"></div>
        </div>
	<?php endif; ?>
        
<?php }?>
<?php
//blog：博客评论列表
function blog_comments($comments){
    extract($comments);
	 ?>
	<?php if($comments): ?>
    <div class="comment com_line">
	<div class="top"><h3>评论</h3><a name="comment"></a></div>
    <ul>
	<?php endif; ?>
	<?php
	foreach($comments as $key=>$value):
	$value['poster'] = $value['url'] ? '<a href="'.$value['url'].'" target="_blank">'.$value['poster'].'</a>' : $value['poster'];
	?>
        <li>
            	<div><h5><a name="<?php echo $value['cid']; ?>"></a>
		<b><?php echo $value['poster']; ?> </b></h5><?php echo $value['date']; ?></div>
		 <img src="http://www.gravatar.com/avatar/<?php echo md5($value['mail']); ?>" width="60" height="60"/>
                <div class="comm">&nbsp;<?php echo $value['content']; ?></div>
        <div class="clear"></div>
    </li >
	<?php endforeach; ?>
		<?php if($comments): ?>
     </ul>
        <div class="bottom"></div>
    </div>
	<?php endif; ?>
<?php }?>
<?php
//blog：发表评论表单
function blog_comments_post($logid,$ckname,$ckmail,$ckurl,$verifyCode,$allow_remark){?>
	<?php if($allow_remark == 'y'): ?>
       <div class="comment_pots">
        <div class="top"><h3>发表评论</h3><a name="comment"></a></div>
    <form method="post"  name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform">
	<input type="hidden" name="gid" value="<?php echo $logid; ?>" />
	<?php if(ROLE == 'visitor'): ?>
	<p>
	<input type="text" name="comname" maxlength="49" value="<?php echo $ckname; ?>"  size="22" tabindex="1">
	<label for="author"><small>昵称</small></label></p>
	<p>
	<input type="text" name="commail"  maxlength="128"  value="<?php echo $ckmail; ?>" size="22" tabindex="2"> 
	<label for="email"><small>邮件地址 (选填)</small></label></p>
	<p><input type="text" name="comurl" maxlength="128"  value="<?php echo $ckurl; ?>" size="22" tabindex="3">
	<label for="url"><small>个人主页 (选填)</small></label>
	</p>
	<?php endif; ?>
	<p><textarea name="comment" id="comment"  rows="10" tabindex="4"></textarea></p>
	<p><div class="comment_yz"><?php echo $verifyCode; ?><input name="Submit" type="submit" id="comment_submit" value="发表评论" /></div></p>
	</form>
        <div class="bottom"></div>



	<?php endif; ?>
<?php }?>